package com.hmdp.utils;


import org.springframework.beans.BeanUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public class BeanCopyUtils {

    public static <O,V> List<V> copyList(List<O> list, Class<V> clazz) {
        //循环读数
        return list.stream()
                .map(o -> copyOne(o,clazz))
                .collect(Collectors.toList());

    }
    public static<O,V> List<V> copyList(List<O> ls,V vo) {
        List<V> articleVos = new ArrayList<>();
        for (O article : ls) {
            BeanUtils.copyProperties(article,vo);
            articleVos.add(vo);
        }
        return articleVos;
    }

    public static <V> V copyOne(Object source, Class<V> clazz) {
        V result=null;
        try {
            result = clazz.newInstance();
            //实现属性copy
            BeanUtils.copyProperties(source,result);

        }  catch (Exception e) {
            e.printStackTrace();
        }
        return result;

    }

}




